package com.awei.study.design.structure.adapter;

/**
 * @Author liweilong
 * @Date 2024/8/7 18:18
 * 类适配器
 */
public class ClassAdapter {
    public static class Computer {
        public String readSd(SdCard sdCard) {
            return sdCard.read();
        }
    }

    public static interface SdCard {
         String read();
         void write(String msg);
    }

    public static class SdCardImpl implements SdCard {

        @Override
        public String read() {
            return "SdCard read : hello SdCard";
        }

        @Override
        public void write(String msg) {
            System.out.println("SdCard write success " + msg);
        }
    }

    public static interface  TfCard {
        String readTf();
        void writeTf(String msg);
    }

    public static class TfCardImpl implements TfCard {

        @Override
        public String readTf() {
            return "TfCard read : hello TfCard";
        }

        @Override
        public void writeTf(String msg) {
            System.out.println("TfCard write success " + msg);
        }
    }

    public static class TfAdapterSd extends TfCardImpl implements SdCard {

        @Override
        public String read() {
            return readTf();
        }

        @Override
        public void write(String msg) {
            writeTf(msg);
        }
    }

    public static void main(String[] args) {
        Computer computer = new Computer();

        SdCardImpl sdCard = new SdCardImpl();

        System.out.println(computer.readSd(sdCard));

        TfAdapterSd sd = new TfAdapterSd();

        System.out.println(computer.readSd(sd));
    }
}
